<?php

namespace app\shop\model;
use app\common\model\BaseModel;
class ShopStoreGoods extends BaseModel
{
    public function specs()
    {
        return $this->hasMany(ShopStoreGoodsSpec::class, 'gid')->where('is_deleted', 0);
    }

    protected function getImageAttr($val){
       $val= explode('|',$val);
       return $this->getImgUrl($val);
    }
    public function cate(){
        return $this->belongsTo('ShopStoreGoodsCate','cate_id');
    }
    protected function getAdvImgAttr($val){
        return $this->getImgUrl($val);
    }
    protected function getLogoAttr($val){
        return $this->getImgUrl($val);
    }
    protected function getSaleCountAttr($val,$data){
       return  ShopStoreGoodsSpec::where('gid',$data['id'])->where('is_deleted', 0)->sum('sale');
    }


}